package com.cxx.service.impl;

import com.cxx.annotation.Autowired;
import com.cxx.annotation.Service;
import com.cxx.annotation.Transactional;
import com.cxx.dao.AccountDao;
import com.cxx.dao.impl.JdbcAccountDaoImpl;
import com.cxx.pojo.Account;
import com.cxx.service.TransferService;

/**
 * @author 应癫
 */
@Service(value = "transferService")
@Transactional
public class TransferServiceImpl implements TransferService {

    // private AccountDao accountDao = new JdbcAccountDaoImpl();
    @Autowired
    private AccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            int a = 1/0;
            accountDao.updateAccountByCardNo(from);


    }
}
